﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace Hong.Pan.UI
{
    public class ImageConvert : IValueConverter
    {
        public object Convert(Object value, Type targetType, Object paramter, CultureInfo culture)
        {
            Debug.WriteLine(paramter);
            BitmapImage bitmap = new();
            //bitmap.UriSource = new Uri("pack://application:,,,/Resources/box.png", UriKind.Absolute);
            PanFileInfo? pf = value as PanFileInfo;
            if (pf != null && pf.icon.Length > 0)
            {
                bitmap.BeginInit();
                //if ((int?)jn["isdir"] == 1)
                //{
                //    bitmap.UriSource = new Uri("/Resources/box.png", UriKind.Relative);
                //}
                //else 
                //{
                //    bitmap.UriSource = new Uri("/Resources/file.png", UriKind.Relative);
                //}
                bitmap.UriSource = new Uri(pf.icon, UriKind.Relative);
                bitmap.EndInit();
            }
            return bitmap;
        }

        public object ConvertBack(Object value, Type targetType, Object paramter, CultureInfo culture)
        {
            return null;
        }
    }
}
